﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPMonitor.DataModel;
using NPMonitor.Implementation;

namespace NPMonitor.Web.UserControls
{
    public partial class Location : System.Web.UI.UserControl
    {
        #region 属性

        public int PoolId
        {
            get { return Convert.ToInt32(hfId.Value); }
            set { hfId.Value = value.ToString(); }
        }

        public string PoolName
        {
            get { return txtPoolName.Text; }
            set { txtPoolName.Text = value; }
        }

        public string Comments
        {
            get { return txtComments.Text; }
            set { txtComments.Text = value; }
        }
        public Locations LocationsInvoke
        {
            get { return this.Page as Locations; }
        }
        #endregion

        #region 方法
        protected void Page_Load(object sender, EventArgs e)
        {
            LocationsInvoke.PhEdit = false;
        }

        protected override void OnPreRender(EventArgs e)
        {
            rfvPoolName.ErrorMessage = string.Format(ValidationString.FieldRequired, "PoolName");
            cvPoolNameCount.ErrorMessage = string.Format(ValidationString.FieldLengthExceeded, "PoolName", "30");
            cvPoolName.ErrorMessage = string.Format(ValidationString.FieldAlreadyExists, "PoolName");
            rfvComments.ErrorMessage = string.Format(ValidationString.FieldRequired, "Comments");
            cvCommentsCount.ErrorMessage = string.Format(ValidationString.FieldLengthExceeded, "Comments", "30");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            MachinePool machinePool = new MachinePool();
            machinePool.PoolId = PoolId;
            machinePool.PoolName = PoolName.Trim();
            machinePool.Comments = Comments.Trim();
            StoreManager.Current.MachineStore.SavePoolInfo(PoolId, machinePool);
            LocationsInvoke.PoolDataBind(-1);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "saveSuccessShow", "saveSuccessShow();", true);
        }

        #endregion
    }
}